<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>掷骰子动画</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
    }

    .dice {
      width: 366px;
      height: 366px;
      background-image: url(./random-dice.webp);
      /* background-position: 0 100%; */
      animation: .2s steps(5, start) random infinite;
      cursor: pointer;
    }

    @keyframes random {
      to {
        background-position: 100% 100%;
      }
    }

    #dice {
      display: none;
    }

    /* +号为毗邻选择器  dice为选中态下的紧跟着的label元素*/
    /* 选中元素后，通过animation-play-state来控制元素的动画状态 */
    #dice:checked+label .dice {
      animation-play-state: paused;
    }

    .dice::before {
      content: "?";
      background-color: rgba(255, 255, 255, .8);
      width: inherit;
      height: inherit;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 320px;
      font-family: Helvetica;
      backdrop-filter: blur(20px);
      -webkit-backdrop-filter: blur(20px);
    }

    #dice:checked+label .dice::before {
      /* display: none; */
      visibility: hidden;
    }
  </style>
</head>

<body>
  <input type="checkbox" id="dice">
  <!-- <h1 class="status">如果点击变红</h1> -->
  <label for="dice">
    <div class="dice">
  </label>

  </div>
</body>

</html>